package com.ins1st.plus.config.shiro;

import com.ins1st.plus.api.system.user.entity.SysUser;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * @program: ins1st-plus
 * @description: shiro工具类
 * @author: coderSun
 * @create: 2019-09-09 13:59
 **/
public class ShiroExt {


    /**
     * 获取subject
     *
     * @return
     */
    public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }


    /**
     * 获取当前用户
     *
     * @return
     */
    public static SysUser getUser() {
        return (SysUser) getSubject().getPrincipal();
    }

    /**
     * 判断是有具有权限
     *
     * @param menuRole
     * @return
     */
    public static boolean hasAuth(String menuRole) {
        return StringUtils.isNotBlank(menuRole) ? getSubject().hasRole(menuRole) : false;
    }
}
